package com.ygglxt.service;

import com.ygglxt.entity.YuanGong;
import com.ygglxt.entity.YuanGongSearch;
import com.ygglxt.util.JdbcUtil;

import java.util.List;

/**
 * 员工业务类
 */
public class YuanGongService {


    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<YuanGong> getListAll(int page, int rows, YuanGongSearch obj) {
        String sql="select * from yuangong where 1=1 ";
        if(obj.getUsername()!=null&&!obj.getUsername().equals("")){
            sql+=" and username like '%"+obj.getUsername()+"%' ";
        }
        if(obj.getSex()!=null&&!obj.getSex().equals("")){
            sql+=" and sex like '%"+obj.getSex()+"%' ";
        }
        if(obj.getGwid()!=null&&!obj.getGwid().equals("")){
            sql+=" and gwid like '%"+obj.getGwid()+"%' ";
        }
        if(obj.getKsxz()!=null&&!obj.getKsxz().equals("")&&obj.getJsxz()!=null&&!obj.getJsxz().equals("")){
            sql+=" and xz BETWEEN "+obj.getKsxz()+" and "+obj.getJsxz();
        }
        if(obj.getKsdate()!=null&&!obj.getKsdate().equals("")&&obj.getJsdate()!=null&&!obj.getJsdate().equals("")){
            sql+=" and rzdate BETWEEN '"+obj.getKsdate()+"' and '"+obj.getJsdate()+"' ";
        }
        sql+=" limit "+page+","+rows;
        List<YuanGong> list= JdbcUtil.executeQuery(sql,null,YuanGong.class);
        return list;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(YuanGongSearch obj) {
        String sql="select * from yuangong where 1=1 ";
        if(obj.getUsername()!=null&&!obj.getUsername().equals("")){
            sql+=" and username like '%"+obj.getUsername()+"%' ";
        }
        if(obj.getSex()!=null&&!obj.getSex().equals("")){
            sql+=" and sex like '%"+obj.getSex()+"%' ";
        }
        if(obj.getGwid()!=null&&!obj.getGwid().equals("")){
            sql+=" and gwid like '%"+obj.getGwid()+"%' ";
        }
        if(obj.getKsxz()!=null&&!obj.getKsxz().equals("")&&obj.getJsxz()!=null&&!obj.getJsxz().equals("")){
            sql+=" and xz BETWEEN "+obj.getKsxz()+" and "+obj.getJsxz();
        }
        if(obj.getKsdate()!=null&&!obj.getKsdate().equals("")&&obj.getJsdate()!=null&&!obj.getJsdate().equals("")){
            sql+=" and rzdate BETWEEN '"+obj.getKsdate()+"' and '"+obj.getJsdate()+"' ";
        }
        List<YuanGong> list= JdbcUtil.executeQuery(sql,null,YuanGong.class);
        return list.size();
    }


    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into yuangong(id,username,age,sex,rzdate,gwid,no,xz) values(?,?,?,?,?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update yuangong set username=?,age=?,sex=?,rzdate=?,gwid=?,no=?,xz=? where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param id
     * @return
     */
    public YuanGong getId(String id) {
        String sql="select * from yuangong where id='"+id+"'";
        List<YuanGong> users= JdbcUtil.executeQuery(sql,null,YuanGong.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from yuangong  where id=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
